package com.runjian.rundo.bmp.kernel.common.logback.utils;

import java.util.Objects;

import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;

/**
 * 日志工具类
 *
 * @author LiuYang
 */
public class LogUtils {

    public static void setTraceLogLevel(Class<?> clazz) {
        setLogLevel(clazz.getName(), "TRACE");
    }

    public static void setDebugLogLevel(Class<?> clazz) {
        setLogLevel(clazz.getName(), "DEBUG");
    }

    public static void setLogLevel(String name, String logLevel) {
        if (Objects.isNull(logLevel)) {
            return;
        }

        try {
            LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory();
            Logger logger = loggerContext.getLogger(name);
            logger.setLevel(Level.valueOf(logLevel));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
